home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 5 / dates.zip / DATES.DOC next >
Text File  |  1987-10-27  |  5KB  |  94 lines

  1.   DATES  --  A unit providing Julian day numbers and date manipulations.
  2.  
  3.   Version 1.00 - 10/26/1987 - First general release
  4.  
  5.   Scott Bussinger
  6.   Professional Practice Systems
  7.   110 South 131st Street
  8.   Tacoma, WA  98444
  9.   (206)531-8944
  10.   Compuserve 72247,2671
  11.  
  12.   This UNIT for Turbo Pascal 4.0 provides a new data type Date, which is a
  13. Julian day number indicating the number of days that have elapsed since
  14. January 1, 1900.  A Date allows you to store any date from January 1, 1900 to
  15. December 31, 2078 in only two bytes.  Also defined is an enumerated type
  16. defining the days of the week.  The available routines support conversion
  17. to/from a day, month and year format to the Date format, checking for valid
  18. dates, adding a number of days, months and years to a Date, conversion to/from
  19. a Date and a string form that can be used for sorting and a routine for
  20. determining the day of the week for a given date.  To include this unit in
  21. your program, add DATES to the USES clause in your main program.
  22.   The advantages of using Julian Date numbers are the savings of much storage
  23. space (2 bytes vs. 6 ASCII characters) and that the number of days between any
  24. two dates is a simple subtraction.  The algorithms used here are adapted from
  25. an article by Gordon King in the June 1983 issue of Dr. Dobb's Journal.  Mr.
  26. King in turn credits Algorithm 199 in "The Collected Algorithms of the ACM"
  27. (1963) by R. G. Tantzen.
  28.  
  29.  
  30. type Date = Word;
  31.     A date is stored as a word variable and represents the number of days
  32.     elapsed since January 1, 1900.
  33.  
  34. type Day = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday);
  35.     A Day variable can take the value of any of these special constants
  36.     representing the days of the week.
  37.  
  38. function ValidDate(Day,Month,Year: integer): boolean;
  39.     This functions checks that the given date is both a valid date and that it
  40.     is within the range of dates that can be stored in a Date variable.  Note
  41.     that no error checking takes place in any of the other routines -- it is
  42.     assumed that input error checking will call this routine and all
  43.     parameters to the other routines will thus have alreay been checked.  Days
  44.     range from 1..31 depending on the month and year, months range from 1..12,
  45.     and years range from 1900..2078.
  46.  
  47. procedure DMYtoDate(Day,Month,Year: integer;var Julian: Date);
  48.     Calculate the Julian day number for the given date and return as a Date.
  49.     Again note that no error checking is taking place in this routine -- if
  50.     the date given doesn't make sense then neither will the result, use
  51.     ValidDate to check for valid dates first if necessary.
  52.  
  53. procedure DateToDMY(Julian: Date;var Day,Month,Year: integer);
  54.     The reciprocal routine for DMYtoDate, this procedure takes a Julian day
  55.     number and returns the day, month and year.
  56.  
  57. function BumpDate(Julian: Date;Days,Months,Years: integer): Date;
  58.     This routine adds (or subtracts) a given number of days, months and years
  59.     from the Date.  Months and years are added first before days are added.
  60.     Note that no overflow or underflow checking is performed on the
  61.     calculation, be sure that the resulting date will be in the valid range
  62.     for a Date variable.
  63.  
  64. function DayOfWeek(Julian: Date): Day;
  65.     This routine returns the day of the week for the given date.  This
  66.     information can be used directly, or supplied to the DayString routine
  67.     below to obtain a string representation of the day of the week.
  68.  
  69. function DayString(WeekDay: Day): string;
  70.     This routine takes a Day value and converts it into a string with the name
  71.     of the day for use in output.  The first letter of each is capitalized.
  72.  
  73. function MonthString(Month: integer): string;
  74.     This routine takes an integer from 1..12 and converts it into a string
  75.     with the name of the month for use in output.  The first letter of each is
  76.     capitalized.
  77.  
  78. function DateToStr(Julian: Date): string;
  79.     Returns a two character string representing the Date suitable for use
  80.     in standard string sorts or comparisons.  For example, the result could
  81.     be concatenated to a key for use with the Database Toolbox.
  82.  
  83. function StrToDate(StrVar: string): Date;
  84.     The reciprocal function to DateToStr, this converts a sortable string back
  85.     into a Date value.
  86.  
  87. const BlankDate = $FFFF;
  88.     This special constant is not in the valid range for a Date variable and
  89.     can be used to represent an non-entry, blank entry, or not-a-real-date in
  90.     input and output routines.  Do not supply this value to any routines
  91.     expecting a Date value.  If you decide to use this constant, it is
  92.     expected that you will check for this special value before calling any of
  93.     the above routines.
  94.